<?php
/**
 * vim: et ts=4 sts=4 sw=4 fdm=marker
 *
 * 测试controller 
 *
 * @author	wang Penghai <china_php@hotmail.com>
 * @copyright 2008 5e6d Corporation.
 * @version   $Id: config.php 29 2009-03-10 14:30:18Z wph $
 */
pf_load::init('admin_class_admin');
class admin_action extends pf_controller{
	public function __construct()
	{
		parent::__construct();
	}

	public function index()
	{
		$user_obj = pf_load::init('admin_model_admin');
		$argv = array(
			 'fields'=>array('id', 'username', 'password'),
			 //'limit' => 1,
			 //'offset' => 0,
			 'order' => 'updatetime desc',
			 //'group'=>'id'
			 //'where'=> '1=1',
		);
		$user_list = $user_obj->get_user_list($argv);
		$this->assign('user_list', $user_list);
		$this->view('admin_admin_view_admin');
	}
	//添加显示页
	public function add()
	{
		$opt = pf_request::post('opt');
		switch ($opt)
		{
			case 'insert':
				$this->insert();
				break;
			case 'update':
				$this->update();
				break;
			default:
				$this->add_show();
		}
	}
	private function add_show()
	{
		$group_obj = pf_load::init('admin_model_group');
		$argv = array(
			 'fields'=>array('id', 'name'),
			 //'limit' => 1,
			 //'offset' => 0,
			 'order' => 'updatetime desc',
			 //'group'=>'id'
			 //'where'=> '1=1',
		);

		$group_list = $group_obj->get_group_list($argv);
		$this->assign('group_list', $group_list);
		$this->assign('opt', 'insert');
		$this->view('admin_admin_view_admin.add');
	}

	//添加处理
	private function insert()
	{
		$username = pf_request::post('username');
		$password = md5(pf_request::post('password'));
		$email = pf_request::post('email');
		$real_name = pf_request::post('realname');
		$group_id = pf_request::post('groupid');
		$time = time();
		$argv = array(
			'username' => $username,
			'password' => $password,
			'email' => $email,
			'real_name' => $real_name,
			'group_id' => $group_id,
			'createtime' => $time,
			'updatetime' => $time,
		);
		$user_obj = pf_load::init('admin_model_admin');
		$res = $user_obj->insert($argv);
		if (false === $res)
		{
			die('fail');
		}
		echo 'success';
	}
	//编辑显示页
	public function edit()
	{
		$opt = pf_request::post('opt');
		switch ($opt)
		{
			case 'update':
				$this->update();
				break;
			default:
				$this->edit_show();
		}
	}

	private function edit_show()
	{
		$this->add_show();
	}
}
